#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <cerrno>
#include <cstring>
#include <fcntl.h>
#include <unistd.h>
#include <cstdio>
#include <cassert>
#include "comm.hpp"

int main(){

    // 1、不需要创建管道，直接打开
    int wfd = open(fifoname.c_str(), O_WRONLY);
    if(wfd < 0){
        cout << errno << " : " << strerror(errno) << endl;
        exit(1);
    }

    // 2、进行通信
    char buffer[NUM];
    while(1){
        cout << "请输入数据：";
        char *msg = fgets(buffer, sizeof(buffer) - 1, stdin);
        assert(msg);

        //删除fgets读取的'\n'
        buffer[strlen(buffer) - 1] = 0;

        //忽略大小写的比较
        if(strcasecmp(buffer,"quit") == 0){
            break;
        }

        ssize_t n = write(wfd, buffer, sizeof(buffer) - 1);
        assert(n);
    }
    return 0;
}